package com.ruoyi.web.controller.moon;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.EventTracking;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.MoonUser;
import com.ruoyi.moon.service.IMoonUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.moon.domain.MoonReviews;
import com.ruoyi.moon.service.IMoonReviewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评论Controller
 * 
 * @author admin
 * @date 2024-11-05
 */
@RestController
@RequestMapping("/moon/reviews")
public class MoonReviewsController extends BaseController
{
    @Autowired
    private IMoonReviewsService moonReviewsService;

    @Autowired
    private IMoonUserService moonUserService;

    /**
     * 查询评论列表
     */
    @PreAuthorize("@ss.hasPermi('moon:reviews:list')")
    @GetMapping("/list")
    public TableDataInfo list(MoonReviews moonReviews)
    {
        startPage();
        List<MoonReviews> list = moonReviewsService.selectMoonReviewsList(moonReviews);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
    @PreAuthorize("@ss.hasPermi('moon:reviews:export')")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MoonReviews moonReviews)
    {
        List<MoonReviews> list = moonReviewsService.selectMoonReviewsList(moonReviews);
        ExcelUtil<MoonReviews> util = new ExcelUtil<MoonReviews>(MoonReviews.class);
        util.exportExcel(response, list, "评论数据");
    }

    /**
     * 获取评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('moon:reviews:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(moonReviewsService.selectMoonReviewsById(id));
    }

    /**
     * 新增评论
     */
    @PreAuthorize("@ss.hasPermi('moon:reviews:add')")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MoonReviews moonReviews)
    {
        return toAjax(moonReviewsService.insertMoonReviews(moonReviews));
    }

    /**
     * 修改评论
     */
    @PreAuthorize("@ss.hasPermi('moon:reviews:edit')")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MoonReviews moonReviews)
    {
        return toAjax(moonReviewsService.updateMoonReviews(moonReviews));
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('moon:reviews:remove')")
    @Log(title = "评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(moonReviewsService.deleteMoonReviewsById(id));
    }



    /**
     * 详情查看回复、点赞点踩信息
     */
    @PreAuthorize("@ss.hasPermi('moon:reply:query')")
    @GetMapping(value = "/details/{id}")
    public AjaxResult selectDetails(@PathVariable("id") Long id)
    {
        return success(moonReviewsService.selectDetails(id));
    }



    /**
     * 审核
     */
    @PostMapping("/audit")
    public AjaxResult auditSubmit(@RequestBody MoonReviews moonReviews)
    {
        return success( moonReviewsService.auditSubmit(moonReviews));
    }





//    // 用户点赞评论
//    public boolean likeComment(Long userId, Long id) {
//        MoonReviews moonReviews = new MoonReviews();
//        moonReviews.setUserId(userId);
//        moonReviews.setId(id);
//        // 保存点赞记录到数据库
//        moonReviewsService.cave(moonReviews);
//
//
//        return true;
//    }

}
